package org.example.java.jvm.error;

/**
 * 创建线程导致OOM异常
 * VM Args：-Xss2M
 */
public class JavaVMStackOOM {
  private void dontStop() {
    while (true) {
    }
  }

  public void stackLeakByThread() {
    int i = 0;
    while (true) {
      System.out.println(i++);
      Thread thread = new Thread(new Runnable() {
        public void run() {
          dontStop();
        }
      });
      thread.start();
    }
  }

  public static void main(String[] args) throws Throwable {
    JavaVMStackOOM oom = new JavaVMStackOOM();
    oom.stackLeakByThread();
  }
}
